-
- 863 Posts
Hey Ryonn, just create a new resource called 'ajax' and add your 'process.php' code to an uncached snippet on that page. You can then use the MODX api + xPDO to process the form data and do not need to make another DB connection.
Your ajax submit url will be the url for your new 'ajax' resource. Make sense?
-
- 4 Posts
Hi Lucas,
Firstly, thanks for the quick reply.
I am still beginner at ModX, so I dont really get what you mean.
I will try to analyze them one by one based on my modx understanding so far, please let me know if there is something thats incorrect.
- just create a new resource called 'ajax'
wont this be ajax.html ?
there are 4 types of resources in modx: document, weblink, symlink, static resource.
Is it static resource?
and add your 'process.php' code to an uncached snippet on that page.
I do not really understand the 'uncached snippet' part.
so is it: I copy-paste the content of process.php into a snippet, then call the snippet in the 'ajax' resource content: [[process]] ?
- You can then use the MODX api + xPDO to process the form data and do not need to make another DB connection.
This part is a total blank for me.
Could you please give me a guide or reference for this?
Thank you again =)
Basically, if you put your AJAX processing code in a snippet, put that snippet in a resource with a blank template, then use the URL of that resource in your AJAX request, the AJAX will behave exactly as if you were using a separate .php file.
The major advantage to this method over using external .php files is two-fold. One, your processor has the same security as the security setting for the page you put the snippet on. Nobody can simply access the .php code directly, thus creating a possible security hole in your site.
The second advantage is that since it's a snippet in a resource, you have access to all of the MODx functions and features, just as any snippet has. Access to the database is automatic, through the connection MODx opened to process the snippet.
Many, if not all, MODx snippets can be used as AJAX processors in this manner; with Evo I've used eForm this way frequently. I'm sure that FormIt could be used in the same manner, although Formit doesn't generate the form it does process the form submission, so I see no reason why it wouldn't work.
-
- 4 Posts
Hi Whistle and Susan,
Thanks for the reply. I'll try this first and let you know how it goes
Update:
This works great!!!
Thank you for the help & guidance =D
*cheers*
[ed. note: ryonnsan last edited this post 12 years, 5 months ago.]
-
- 1 Posts
@ryonnsan
I am interested in more detail about your implementation as I am trying to do the same basic thing, only with formit. I am newer to modx than you it sounds like. Any help would be fantastically appreciated!
So far I have a form set up and processed with a call to formit (someone else wrote this a year ago), but after reading a few forums on ajax / non-refreshing forms, I feel pretty lost still. I was interested in somehow making a copy of the formit stuff and altering to not refresh the page, but can't even trace the custom parameter "redirectTo" passed to the call, and which I know works if passed a resource id #. When I pass it nothing, it just refreshes the page, which makes sense.
I also created an empty resource that calls a currently empty new snippet where I assume I would somehow call the ajax stuff which may then use, perhaps, one of the formit phps? But I haven't connected this to the rest due to lostness.
Ben
[ed. note: suffhort last edited this post 12 years, 2 months ago.]